﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WebSite.Models.AdjustListModel>" %>
<%@ Import Namespace="WebSite.Models" %>
<%@ Import Namespace="WebSite.App_Code" %>
<%@ Import Namespace="WebSite.App_Data" %>

<%@ Register src="../Shared/BudgetTable.ascx" tagname="BudgetTable" tagprefix="uc_BT" %>
<%@ Register src="../Shared/BudgetFilter.ascx" tagname="BudgetFilter" tagprefix="uc_BF" %>
<%--<%@ Register src="../Shared/PageTool.ascx" tagname="PageTool" tagprefix="uc_PT" %>--%>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	ApproveList
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <link href="../../Scripts/jquery-ui/css/redmond/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" />
    <script type="text/javascript" src="../../Scripts/external/jquery.bgiframe-2.1.2.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery-ui-dialog/jquery.ui.core.js"></script>
	<script type="text/javascript" src="../../Scripts/jquery-ui-dialog/jquery.ui.widget.js"></script>
	<script type="text/javascript" src="../../Scripts/jquery-ui-dialog/jquery.ui.position.js"></script>
	<script type="text/javascript" src="../../Scripts/jquery-ui-dialog/jquery.ui.dialog.js"></script>
    
    <script type="text/javascript" src="../../Scripts/jquery-pending/jquery-pending.js"></script>

    <script type="text/javascript">

		$(document).ready(function () {

            //$("#progressbar").progressbar({ value: false });

            if ('<%=ViewData.ContainsKey("DB.Operation.Result") %>' == "True")
                alert('<%=ViewData["DB.Operation.Result"] %>');
            
			<% if(Model.PostingEvent == L_PageEvent.B_AppoverList_Import || Model.PostingEvent == L_PageEvent.B_AppoverList_ImportConfirm){ %>
				<% if (Session["Budget.Data.Review"] != null || ViewData["Budget.Data.Review"] != null) { %>
					$(function () {
						$("#dialog-UploadReview").dialog({
							height: 500,
							width: 800,
							modal: true
						});
					});
				<% } %>
			<% } %>
        });

		function Pending(on_off) {

            if (on_off) {

                $("#dialog-Wait").pending({
                    height: 30,
                    width: 24,
                    modal: true
                });
            }
            else {

                $("#dialog-Wait").pending(false);
            }
        }

		function openUploadWin() {

            $(function () {
                $("#dialog-UploadTemplate").dialog({
                    height: 240,
                    width: 500,
                    modal: true
                });
            });
        }

    	function GetSelectID() {

    		var sel = $("input[mark=Select]:checked", $("#QueryTable")).next();
    		var Pjs = ""

    		for (var i = 0; i < sel.length; i++) {
    			Pjs = Pjs + sel.get(i).value + ";";
    		}

    		return Pjs;
    	}

        function GetSelectStatus() {

    		var sel = $("input[mark=Select]:checked", $("#QueryTable")).next().next();
    		var Pjs = ""

    		for (var i = 0; i < sel.length; i++) {
    			Pjs = Pjs + sel.get(i).value + ";";
    		}

    		return Pjs;
    	}

    	function ecFilter(sender) {

    		if ($(sender).val() == "+") {
    			$(sender).val("-");
    			$("#divFilter").show();
    			$("#ShowFilter").attr("checked", "checked");

    		}
    		else {
    			$(sender).val("+");
    			$("#divFilter").hide();
    			$("#ShowFilter").removeAttr("checked");
    		}
    	}

		function Posting(event, id) { $("#PostingEvent").val(event); $("#PostingID").val(id); }

		function OnQuery() { Pending(true); Posting('<%=L_PageEvent.B_AdjustList_Qury %>', null); }
		function ToClose() {
            
            var sl = GetSelectStatus();
            
            if(sl.indexOf("<%=((int)L_BudgetStatus.Use).ToString() %>") >= 0 || sl.indexOf("<%=((int)L_BudgetStatus.Close).ToString() %>") >= 0)
            {
                alert("处于【启用】和【关闭】状态的预算将不会被关闭");
            }
            
            Pending(true);             
            Posting('<%=L_PageEvent.B_AdjustList_Close %>', GetSelectID()); 
        }
		function ClostToAdjust() { Pending(true); Posting('<%=L_PageEvent.B_AdjustList_CloseToAdjust %>', GetSelectID()); }
		function ClosetToComplete(){ Pending(true); Posting('<%=L_PageEvent.B_AdjustList_CloseToComplete %>', GetSelectID()); }
		function CloseToOpen(){ Pending(true); Posting('<%=L_PageEvent.B_AdjustList_CloseToOpen %>', GetSelectID()); }

	</script>

    <% Html.BeginForm("AdjustList", "Budget", FormMethod.Post, new { enctype = "multipart/form-data" }); %>
	
    <%=Html.HiddenFor(o => o.PostingEvent, new { id = "PostingEvent" })%>
    <%=Html.HiddenFor(o => o.PostingID, new { id = "PostingID" })%>
    <%=Html.CheckBoxFor(o => o.ShowFilter, new { id = "ShowFilter", style = "display:none" }) %>
    <input type="hidden" id="PostingStatus" />

    <div style=" border:1px solid #385D8A; padding:10px; width:600px; background-color:White" >

        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td><a style=" margin:0px 3px 0px 3px">条件过滤 </a> </td>
                <td>
                    <div class="budget-button-no-02">
                        <input type="button" value="<%if (!Model.ShowFilter) { %>+<% } else { %>-<% } %>" 
                            class="budget-submit-no-02" onclick="ecFilter(this)" hidefocus="true" />
                    </div>
                </td>
            </tr>
        </table>

        <br />

        <div style="display:<%if (!Model.ShowFilter) { %>none<% } %>" id="divFilter">
            <uc_BF:BudgetFilter ID="ucFilter" runat="server" />
        </div>
        
        <div class="budget-button-no-01" style="width:50px;">
            <input type="submit" value="查询" class="budget-submit-no-01" hidefocus="true" onclick="OnQuery()" />
        </div>

    </div>    

    <br />

    <uc_BT:BudgetTable ID="ucMain" runat="server" />

    <br />

    <%--<uc_PT:PageTool ID="ucPage" runat="server" />

    <br />--%>

    <% if (Model.QueryResult.Count > 0) { %>
        
        <table border="0" cellpadding="0" cellspacing="0">
            <tr>
                <td style="padding-right:10px">
                    <div class="budget-button-no-01" style="width:100px">
                        <input type="submit" class="budget-submit-no-01" onclick="ToClose()" value="关闭" hidefocus="true" />
                    </div>                
                </td>
                <td style="padding-right:10px">
                    <div class="budget-button-no-01" style="width:100px">
                        <input type="submit" class="budget-submit-no-01" onclick="ClostToAdjust()" value="关闭 -> 调整" hidefocus="true" />
                    </div>                
                </td>
                <td style="padding-right:10px">
                    <div class="budget-button-no-01" style="width:100px">
                        <input type="submit" class="budget-submit-no-01" onclick="ClosetToComplete()" value="关闭 -> 完成" hidefocus="true" />
                    </div>                
                </td>
                <td style="padding-right:10px">
                    <div class="budget-button-no-01" style="width:120px">
                        <input type="submit" class="budget-submit-no-01" onclick="CloseToOpen()" value="关闭 -> 开发提交" hidefocus="true" />
                    </div>                
                </td>
            </tr>        
        </table>

    <% } %>
    
	<div id="dialog-UploadTemplate" title="审批提交" style=" display:none">
		<table border="0" cellpadding="0" cellspacing="0" style=" width:100%" >
			<tr>
				<td colspan="4" style=" font-size:large; text-align:center; padding:10px 0px 5px 0px">
					该页面用于审批预算<br />
				</td>
			</tr>
			<tr>
				<td style=" width:50px"></td>
				<td style="color:Red;">
					注意：
				</td>
				<td style="color:Red; ">
					1. 每次只能上传一个文件                    
				</td>
				<td style=" width:50px"></td>
			</tr>
			<tr>
				<td style=" width:50px"></td>
				<td></td>
				<td style="color:Red;">
					2.每个文件中可以包含多个预算，但必须为同一个预算类别
				</td>
				<td style=" width:50px"></td>
			</tr>
			<tr>
				<td colspan="4" align="center" style=" padding:40px 0px 0px 0px">                        
					<input type="file" name="uploadBudget" style=" width:300px; text-align:left" class="budget-button-no-01" />
					<input type="submit" value="提交" class="budget-button-no-01" onclick="OnUpload()" />
				</td>
			</tr>
		</table>
	</div>

	<div id="dialog-UploadReview" title="审批确认" style=" display:none; padding:20px">
            
		<span style=" font-size:large;">
		以下为本次上传的预算信息的检查结果。<br />
		请确认每项预算的处理方案和检查中发现的错误
		</span>
		<br />
		<br />
		<% List<TemplateSheetItem> Table = new List<TemplateSheetItem>();

			if (Session["Budget.Data.Review"] != null)
				Table = (List<TemplateSheetItem>)Session["Budget.Data.Review"];
			else if (ViewData["Budget.Data.Review"] != null)
				Table = (List<TemplateSheetItem>)ViewData["Budget.Data.Review"];
		%>

		<%if (Table.Count > 0) { %>
			<% int ErrorCount = 0; %>
			<table border="0" cellpadding="0" cellspacing="0" class="budget-table-no-01">
				<thead>
				<tr>
					<td>编制单位</td>
					<td>项目名称</td>
					<td>项目负责人</td>
					<td>是否垫支</td>
					<td>垫支金额</td>
					<td>预算金额</td>
					<td>检查结果</td>
					<td class="last">处理方案</td>
				</tr>
				</thead>
				<tbody>
				<%  foreach (TemplateSheetItem Sheet in Table) 
					{
						Dictionary<String, ExcelSheetCellItem> Row = Sheet.BugetInfo;
						if (!Sheet.IsOK)
							ErrorCount++;
				%>
				<tr>
					<td><%=Row["编制单位"].Text %></td>
					<td><%=Row["项目名称"].Text %></td>
					<td><%=Row["项目负责人"].Text %></td>
					<td><%=Row["是否垫支"].Text%></td>
					<td><%=Row["垫支金额"].Text %></td>
					<td><%=Row["预算金额"].Text %></td>
					<td><%=Row["检查结果"].Text %></td>
					<td><%=Row["处理方案"].Text %></td>
				</tr>
				<% } %>
				</tbody>
			</table>

			<% if (ErrorCount == 0 && Session["Budget.Data.Review"] != null) { %>
				<br />
				<input type="submit" value="确认提交" class="budget-button-no-01" onclick="OnUploadConfirm()" />
			<% }  %>
		<% } %>

	</div>

	<div id="dialog-Wait" style=" text-align:center; padding:0px; display:none; overflow:hidden">
		<img src="../../Style/Img/loading-01.GIF" />
	</div>

    <% Html.EndForm(); %>
</asp:Content>
